Learn R Programming

VeryLargeIntegers (version 0.2.1)

23. Fibonacci numbers: Fibonacci Numbers Tools for vli Objects

Description

The Fibonacci Sequence is defined as follows:

x[1] = 0,

x[2] = 1,

...

x[n] = x[n-1] + x[n-2].

A positive integer is said to be a Fibonacci Number if it is an element of the Fibonacci Sequence.

The function Fibonacci(m, output) computes and displays the first m elements of the Fibonacci Sequence.

The function nthFibonacci(n) computes and displays the n-th element of the Fibonacci Sequence.

The function is.Fibonacci(x) says whether or not x is a Fibonacci Number.

Usage

Fibonacci(m, output = "print")

# S3 method for default Fibonacci(m, output = "print")

# S3 method for numeric Fibonacci(m, output = "print")

nthFibonacci(n)

# S3 method for default nthFibonacci(n)

# S3 method for numeric nthFibonacci(n)

# S3 method for vli nthFibonacci(n)

is.Fibonacci(x)

# S3 method for default is.Fibonacci(x)

# S3 method for numeric is.Fibonacci(x)

# S3 method for vli is.Fibonacci(x)

Value

The function Fibonacci(m, output) returns a list of objects of class vli or the result displayed on the screen, depending on the output argument.

The function nthFibonacci(n) returns a object of class vli.

The function is.Fibonacci(x) returns a boolean.

Arguments

m

object of class vli or 32 bits integer

output

chosen way for objects being returned: 'list' to return the result as a list of vli objects or 'print' (by default) to simply display the result on the screen; character

n

vli class object or 32 bits integer

x

vli class object or 32 bits integer

Author

Javier Leiva Cuadrado

Examples

Run this code
Fibonacci(200)

n <- as.vli("50000")
nthFibonacci(n)

x <- as.vli("5358359254990966640871840")
is.Fibonacci(x)

y <- x + 1
is.Fibonacci(y)

Run the code above in your browser using DataLab